package com.cjg.eightLock;

import java.util.concurrent.TimeUnit;

public class demo01 {
    public static void main(String[] args) throws InterruptedException {
        person person = new person();
        //synchronized 锁的是对象 ,两个线程锁的都是 person 所有eat先执行
        new Thread(()->{
            person.eat();
        }).start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{
            person.sleep();
        }).start();
    }
}

class person{
    public synchronized void eat(){
        System.out.println("eat");
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public synchronized void sleep(){
        System.out.println("sleep");
    }
}
